package frontend.product.controller;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import backend.product.manager.ProductAttributeManager;
import backend.product.manager.ProductAttributeSetManager;
import backend.product.manager.ProductManager;

import com.opensymphony.xwork2.ActionSupport;

import core.attribute.model.AttributeSet;
import core.product.model.Product;
import core.product.model.ProductAv;

public class ProductDetailAction extends ActionSupport
{
	private static final long serialVersionUID = 14343L;
	//private SearchManager searchManager ;
	private String searchkey ;
	private String sku ;
	private Product product;
	ProductAttributeSetManager pasm;
	ProductAttributeManager pam;
	ProductManager pm;
	List<ProductAv> productAttribute;
	int reviewCount;
	int rating;
	//private List<Product> products ;
	
	public ProductDetailAction()
	{
		pm=new ProductManager();
		 pam=new ProductAttributeManager();
		pasm=new ProductAttributeSetManager();
		
	}
	
	public String execute() 
	{
		List<ProductAv> productAttributetmp = new ArrayList<ProductAv>();
		//this.searchkey = this.getSearchkey();
		this.product=pm.getProductBySku(sku);
		Iterator<AttributeSet> attrsItr = pasm.getAssignedAttributeSet(this.product).iterator();		
		while(attrsItr.hasNext())
		{
			AttributeSet localAttrS = attrsItr.next();
			productAttributetmp.addAll(pasm.getProductAvByAttributeSetAndProduct(this.product,localAttrS));
		}
		this.setProductAttribute(productAttributetmp);
		rating = pam.getRating(product);
		reviewCount = pam.getReviewCount(product);
		//this.products = searchManager.getSimpleSearchResult(this.searchkey);
		return SUCCESS ;
	}
	
	public int getReviewCount() {
		return reviewCount;
	}

	public void setReviewCount(int reviewCount) {
		this.reviewCount = reviewCount;
	}

	public int getRating() {
		return rating;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public String getSearchkey() {
		return searchkey;
	}
	public void setSearchkey(String searchkey) {
		this.searchkey = searchkey;
	}
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	public List<ProductAv> getProductAttribute() {
		return productAttribute;
	}
	public void setProductAttribute(List<ProductAv> productAttribute) {
		this.productAttribute = productAttribute;
	}
	public String getSku() {
		return sku;
	}
	public void setSku(String sku) {
		this.sku = sku;
	}
	
}
